# SpecialText.py: 
# Written by Victor Luna Freire - victorclf@live.com
# Copyright (c) Victor Luna Freire. All rights reserved.
# Monday, November 02, 2009 1:59:29 AM
# Python 2.6.2
import math

class GlowingText:
    def __init__(self, font, text, pos, speed, color_from, color_to, bgcolor=None):
        self.text = text
        self.font = font
        self.pos = pos
        self.color_from = color_from
        self.color_to = color_to
        self.current_color = list(color_from)
        self.speed = speed
        self.counter = 0
        self.bgcolor = bgcolor                
        
    def increase_color(self, index, mult_factor):
        interval = (self.color_to[index] - self.color_from[index]) / 2.0
        self.current_color[index] = self.color_from[index] + interval + math.sin(self.counter) * (interval)
                        
    
    def adjust_time(self, mult_factor):
        self.counter += self.speed * mult_factor
        self.counter %= math.pi * 2
        for i in xrange(3): self.increase_color(i, mult_factor)
        
        
    def draw(self, screen):
        if not self.bgcolor:
            screen.blit(self.font.render(self.text, True, self.current_color), self.pos)
        else:
            screen.blit(self.font.render(self.text, True, self.current_color, self.bgcolor), self.pos)
    
    
    def main(self, screen, mult_factor):
        self.draw(screen)
        self.adjust_time(mult_factor)
        
        

